package com.chzc.fm.duotin.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.home.RecommendColumn;
import com.chzc.fm.duotin.bean.home.RecommendData;
import com.chzc.fm.duotin.bean.home.RecommendDataList;
import com.chzc.fm.duotin.utils.LogUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/6/24.
 */
public class HomePannel extends RelativeLayout {
    private LinearLayout llroot;
    private TextView tvType,tvMore;
    public HomePannel(Context context, RecommendData data) {
        super(context);
        initViews(context);
        setData(data);
    }

    public HomePannel(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }
    private  void initViews(Context context){
        inflate(context, R.layout.fragment_home_pannel,this);
        tvType = (TextView) findViewById(R.id.tv_type);
        tvMore = (TextView) findViewById(R.id.tv_more);
        llroot = (LinearLayout) findViewById(R.id.llroot);

    }
    public void setData(RecommendData data){
        RecommendColumn column = data.getColumn();
        tvType.setText(column.getTitle());
        tvMore.setText(column.getRedirect_words());
        List<RecommendDataList> dataLists = data.getData_list();
        LogUtil.e("pannel"+"==="+dataLists);
        final HomeLayout layout = new HomeLayout(getContext(),dataLists);
        final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
       // params.gravity = Gravity.CENTER_HORIZONTAL;
        layout.setLayoutParams(params);

        llroot.addView(layout,1);

    }
}
